﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin.member
{
    public partial class member_rank_add : BaseAdmin
    {

        // Methods
        private void Bind()
        {
            if (base.Request.QueryString["rankid"] != null)
            {
                string sql = "select * from DB_memberank where rankid=" + base.Request.QueryString["rankid"] + "";
                DataTable table = new DataTable();
                table = SQLAccess.GreatDs(sql).Tables[0];
                this.rank.Value = table.Rows[0]["rank"].ToString();
                this.score1.Value = table.Rows[0]["score1"].ToString();
                this.score2.Value = table.Rows[0]["score2"].ToString();
                this.score3.Value = table.Rows[0]["score3"].ToString();
                this.isshow.Checked = (bool)table.Rows[0]["isshow"];
                this.ismember.Checked = (bool)table.Rows[0]["ismember"];
            }
            else
            {
                this.score1.Value = "0";
                this.score2.Value = "0";
                this.score3.Value = "100";
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string str3 = "0";
            str3 = re.maxid("", "Db_Memberank", "rankid");
            if (base.Request.QueryString["rankid"] != null)
            {
                SQLAccess.DoSql(string.Concat(new object[] { "update DB_memberank set rank='", re.replace(this.rank.Value), "',score1=", re.replace(this.score1.Value), ",score2=", re.replace(this.score2.Value), ",isshow=", this.isshow.Checked ? "1" : "0", ",ismember=", this.ismember.Checked ? "1" : "0", ",score3=", re.replace(this.score3.Value), " where rankid=", base.Request.QueryString["rankid"], "" }));
            }
            else
            {
                SQLAccess.DoSql(string.Concat(new object[] { "insert into DB_memberank (rankid,rank,score1,score2,isshow,ismember,score3) values (", str3.ToString(), ",'", re.replace(this.rank.Value), "',", re.replace(this.score1.Value), ",", re.replace(this.score2.Value), ",", this.isshow.Checked ? "1" : "0", ",", this.ismember.Checked ? "1" : "0", ",", re.replace(this.score3.Value), ")" }));
                string sql = "select proid,proprice1 from DB_Shoppro";
                DataTable table = SQLAccess.GreatDs(sql).Tables[0];
                if (table.Rows.Count > 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        SQLAccess.DoSql("insert into DB_Memberprice (rankid,productid,price) values (" + str3.ToString() + ",'" + row["proid"].ToString() + "'," + row["proprice1"].ToString() + ")");
                    }
                }
            }
            base.Response.Write("<script language='javascript'>window.location.href='member_rank.aspx';</script>");
            base.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.Bind();
            }
        }

    }
}